<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>蒋路的检查申请</title>
</head>
<body>
	<script type="text/javascript"> 
	
	$.extend($.fn.validatebox.defaults.rules, {
		nameToKind: {
	        validator: function(value){	        	
				var PDcprekind=$("#cprekind").combobox("getText");			
					$.ajax({
		                type: "Post",
		                url: "tocheckProjPJ",//根据名字查看种类
		                data: {price:value},
		                success: function (data) {
		                	$("#cprekind").combobox("setText",data[0].kind);
		                }
		            });				
	        }
	    }
	});
       
	function QueryCourseByCollege() {  
	    var CollegeID = $('#cprekind').combobox('getValue');  
	    if (CollegeID != null || CollegeID !="") {    	      
	            var cmbSchoolYear = $('#cpreId').combobox({ 	            
	                url:'tocheckProjKind?kind='+ CollegeID,	   
	                editable: false,  
	                method: 'get',  
	                valueField: 'cprProject',  
	                textField: 'cprProject',  
	            });         
	    }  
	}  
	
		$(function(){
			var date = new Date();		
			var y = date.getFullYear();  
			var m = date.getMonth() + 1;  
			m = m < 10 ? '0' + m : m;  
			var d = date.getDate();  
			d = d < 10 ? ('0' + d) : d;  
			var needDate=y + '-' + m + '-' + d;  	
			 
			$("#ExamineApplyadd").linkbutton({
				onClick:function(){
					var a_yhic=$("#a_yhic").textbox("getText");
					var b_ygid=$("#b_ygid").textbox("getText");
					var c_kcid=$("#c_kcid").textbox("getText");
					if(a_yhic==null || a_yhic=="" ){
						$.messager.alert("温馨提示","如需申请检查或化验，请先呼叫病人！")
					}else{
						$('#ExamineApplywin').window({'title': "填写申请单"});
						$("#ExamineApplywin").window('open');
						$("#ExamineApplyff").form("clear");						
						$("#eDate").textbox("setValue",needDate);
						$("#ieId").textbox("setValue",a_yhic);
						$.ajax({
			                type: "Post",
			                url: "to_idToTbstaff",
			                data: {staffNo:b_ygid  },
			                success: function (data) {
			                    $("#ePhysician").textbox("setText",data[0].staffName);			                    
			                    $.ajax({
			                        type: "Post",
			                        url: "to_idTofindALLdepartment",
			                        data: {bmid:c_kcid},
			                        success: function (data) {
			                        	$("#eOffice").textbox("setText",data[0].departmentName);			                        	
			                        }
			                    });
			                }
			            });
						var PDcprekind=$("#cprekind").combobox("getText");
						if(PDcprekind==null || PDcprekind==""){
								$('#cpreId').combobox({ 	            
				                url:'tocheckprojectqueryAll',	   
				                editable: false,  
				                method: 'get',  
				                valueField: 'cprProject',  
				                textField: 'cprProject',  
				            });   
						}
						
						
					}														
				}
			});
			
			$("#ExamineApplyagain").linkbutton({  				
				onClick : function() {
					var of=$("#eOffice").textbox("getText");
					$("#eOffice").textbox("setValue",of);					
					var ep=$("#ePhysician").textbox("getText");
					$("#ePhysician").textbox("setValue",ep);
					$('#ExamineApplyff').form('submit', {
						onSubmit : function() {
						},				
						success : function(data) {				
							var json = eval("("+data+")");
							$.messager.alert("申请成功", json.reason);
							$.ajax({
				                type: "Post",
				                url: "tomaxExamineApply",
				                data: {  },
				                success: function (data) {
				                	$("#ExamineApplytab").datagrid({
									       rowStyler: function (index, row) {
									            if (row.eId== data) {
									                 return 'background-color:#6293BB;color:#fff;';
									            }
									       }
									}); 
				                }
				            });					
							//重新加载数据
							$("#ExamineApplytab").datagrid("reload");
							$("#cprekind").combobox('setValue',"");
							$("#cprekind").combobox("setText","");
						}
					});
				}
			});	
			
			$("#ExamineApply-save").linkbutton({  
				onClick : function() {
					var of=$("#eOffice").textbox("getText");
					$("#eOffice").textbox("setValue",of);					
					var ep=$("#ePhysician").textbox("getText");
					$("#ePhysician").textbox("setValue",ep);
					$('#ExamineApplyff').form('submit', {
						onSubmit : function() {
						},				
						success : function(data) {				
							var json = eval("("+data+")");
							$.messager.alert("申请成功", json.reason);
							$.ajax({
				                type: "Post",
				                url: "tomaxExamineApply",
				                data: {  },
				                success: function (data) {
				                	alert(data);
				                	$("#ExamineApplytab").datagrid({
									       rowStyler: function (index, row) {
									            if (row.eId== data) {
									                 return 'background-color:#6293BB;color:#fff;';
									            }
									       }
									}); 
				                }
				            });				
							//关闭窗口
							$("#cprekind").combobox('setValue',"");
							$("#cprekind").combobox("setText","");
							$("#ExamineApplywin").window('close');
							//重新加载数据
							$("#ExamineApplytab").datagrid("reload");
							$(this).form("clear");
						}
					});
				}
			});	
		
			$("#ExamineApplycancel").linkbutton({
				onClick : function() {
					$('#ExamineApplyff').form("clear");
					$("#ExamineApplywin").window("close");
				}
			});
			$("#ExamineApplyref").linkbutton({
				onClick:function(){						
					$("#ExamineApplytab").datagrid({
						 url: 'to_ExamineApplypage'
					});
				}
			});
			$('#ExamineApplysearch').searchbox({
			    searcher:function(value,name){
			    	if(name=="姓名"){
			    		$.ajax({
			                type: "Post",
			                url: "to_nametoic",
			                data: {name:value},
			                success: function (data) {
			                	if(data==null || data==""){
			                		$.messager.alert("温馨提示", "没有该用户的任何信息！");	
			                	}else{
			                		$("#ExamineApplytab").datagrid({
							    		url:'icidtoexamineapply',
							    		queryParams: {
							    			ieId:data 
							    		}
							    	});
			                	}			                				           	
			                }
			            });
			    		
			    	}else if(name=="身份证号"){
			    		$.ajax({
			                type: "Post",
			                url: "to_iccardtoic",
			                data: {iIdentityCard:value},
			                success: function (data) {
			                	if(data==null || data==""){
			                		$.messager.alert("温馨提示", "没有该用户的任何信息！");	
			                	}else{
			                		$("#ExamineApplytab").datagrid({
							    		url:'icidtoexamineapply',
							    		queryParams: {
							    			ieId:data 
							    		}
							    	});
			                	}			                				           	
			                }
			            });
			    	}else{	
			            $("#ExamineApplytab").datagrid({
							 url:'icidtoexamineapply',
							 queryParams: {
							 	ieId:value 
							 }
						});			                				                				           				                			           
			    	}    	
			    	
			    }
			});
		});
	</script>
	
	<table id="ExamineApplytab" class="easyui-datagrid"
			data-options="
				fitColumns:true,
				fit:true,
				rownumbers: true,
			    url: 'to_ExamineApplypage',
				border:false ,
				pagination:true,
				toolbar: '#ExamineApply_btn',
				pageSize: 14,
				pageList:[14,28,42,56]
			">
			<thead>
				<tr>
					<th class="ident" data-options="field:'eId',checkbox:true">申请编号</th>
					<th class="ident" data-options="field:'ieId',width:10">IC卡号</th>
					<th class="ident" data-options="field:'eOffice',width:15,editor:'textbox'">科室</th>
					<th class="ident" data-options="field:'ePhysician'">医师</th>
					<th class="ident" data-options="field:'cpreId'">检查项目</th> 
					<th class="ident" data-options="field:'eDate',width:10,formatter:function(value){
                          var unixTimestamp = new Date(value);  
                          return unixTimestamp.toLocaleDateString();}">申请日期
                    </th> 
				</tr>
			</thead>
		</table>
	
	<div id="ExamineApply_btn">
		<a id="ExamineApplyadd" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">申请</a> 
		<a id="ExamineApplyref"class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">显示全部记录</a>
		<input id="ExamineApplysearch" class="easyui-searchbox" 
			data-options="menu:'#ExamineApplyee',width:220,prompt:'请输入。。。。'">
	</div>
	<div id="ExamineApplyee" style=" width:90px">
		<div date-options="name:'name'">卡号</div>
		<div date-options="name:'name'">姓名</div>
		<div date-options="name:'name'">身份证号</div>
	</div>
	<div>
		<div id="ExamineApplywin" class="easyui-window"
			style="padding: 10px;line-height: 150%;"
			data-options="
		     width: 465,
		     height:204,
		     closed: true,
		     title:'申请检查操作'
			">		
				<form id="ExamineApplyff" action="addExamineApply" method="post">
					<table>
						<tr>
							<td>
								<div class="item">
									<input id="ieId" name="ieId"  class="easyui-textbox" data-options="label: 'IC卡号:', width: 200,labelWidth:65">
								</div>
							</td>
							<td>
								<div class="item">
									<input id="eOffice" name="eOffice"  class="easyui-textbox" data-options="label: '科室:', width: 200,labelWidth:65">								
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="item">
								<input id="ePhysician"  name="ePhysician" class="easyui-textbox" data-options="label: '医师:', width: 200,labelWidth:65">									
								</div>
							</td>
							<td>
							    <div class="item">
							     <input id="eDate" name="eDate" ReadOnly="readonly" class="easyui-textbox" data-options="label: ' 申请日期:', width: 200,labelWidth:65">
								</div>
							</td>
						</tr>
						<tr>
							<td>
							   <div class="item">
							        <select id="cprekind" class="easyui-combobox"  name="cpreIdkind" data-options="label:'种类:', editable:false,labelWidth:65,width:200,panelHeight:'auto',
							        		onChange:function(){  
                                           QueryCourseByCollege();  
                                         } ">
									    <option value="超声波检查">超声波检查</option>                   
									    <option value="心电图检查">心电图检查</option>
									    <option value="X线检查">X线检查</option>
									    <option value="脑肌电图检查">脑肌电图检查</option>
									    <option value="胃镜检查">胃镜检查</option>
									    <option value="病理检查">病理检查</option>
									</select>							   																
								</div>
							</td>
							<td>						
								 <div class="item">
								 	<select id="cpreId" class="easyui-combobox"  name="cpreId" data-options="validType: ['nameToKind'],label:'项目:', editable:false,labelWidth:65,width:200,panelHeight:'auto', 
                                           panelHeight:'auto'                                    
									 ">
									</select>							  		
								</div>
							</td>
						</tr>
						
						<tr>
							<td>
								<div class="item">
									<a id="ExamineApply-save" class="easyui-linkbutton"data-options="iconCls:'icon-icNo'"style="width:90px">结束</a>
									<a id="ExamineApplyagain" class="easyui-linkbutton"data-options="iconCls:'icon-icNo'"style="width:90px">继续</a>
								</div>
							</td>
							<td>
								<div class="item">
									<a id="ExamineApplycancel" class="easyui-linkbutton"data-options="iconCls:'icon-icOk'"style="width:90px;">取消</a>
								</div>
							</td>
						</tr>
					</table>	
				</form>
			
		</div>
	</div>
</body>
</html>